from dataclasses import asdict

from Attriabte.DTO import ColorHoverWidgetDto
from . import BasicHoverLabel


class ColorHoverLabel(BasicHoverLabel.BasicHoverLabel):
    def __init__(self, win, config: ColorHoverWidgetDto, click=None):
        super().__init__(win, config,click)
        self.conf: ColorHoverWidgetDto = self.arg[-1]

    def hover(self, e):
        print(self.conf.hover_bg, self.conf.hover_fg)
        self.label['fg'] = self.conf.hover_fg
        self.label['bg'] = self.conf.hover_bg

    def leave(self, e):
        self.label['fg'] = self.conf.fg
        self.label['bg'] = self.conf.bg

    def update_config(self, new_config:ColorHoverWidgetDto):
        new = asdict(new_config)
        old = asdict(self.conf)
        for k, v in new.items():
            print(k,v)
            old[k] = v
        print(old)
        self.conf = ColorHoverWidgetDto(**old)
